

const fruitNum10 = function(num){
	if(!num || typeof num == 'object') return 0;
	return num % 10 == 0 ? (num /10).toFixed(0) : (num / 10).toFixed(1); 
}

const numToWan = function(num){
	if(num >= 10000) return (num / 10000).toFixed(2) + 'w';
	return num;
}

const timeChinese = function(value){
  let theTime = parseInt(value); // 秒
  let middle = 0; // 分
  let hour = 0; // 小时

  if (theTime > 60) {
    middle = parseInt(theTime / 60);
    theTime = parseInt(theTime % 60);
    if (middle > 60) {
      hour = parseInt(middle / 60);
      middle = parseInt(middle % 60);
    }
  }
  let result = "" + parseInt(theTime) + "秒";
  if (middle > 0) {
    result = "" + parseInt(middle) + "分" + result;
  }
  if (hour > 0) {
    result = "" + parseInt(hour) + "小时" + result;
  }
  return result;
}

const moneyFenToYuan = function(num) {
    if (num == null || num == "" || typeof(num) == undefined) {
        return 0;
    } else {
        let tempNum = (num/100).toFixed(2);
        return Number(tempNum);
    }
}

const numberFormat  = function(val) {
  if(!val || val<=0) return 0;
  if(val < 10000 ) return val;
  return val = (val / 10000).toFixed(2) + 'w';
}

const chineseDay  = function(isDate) {
  if(!isDate) return '';
  var d = new Date(isDate);
  var year = d.getFullYear();
  var mon = d.getMonth() + 1;
  var day = d.getDate();
  let hours = d.getHours();
  let minutes = d.getMinutes();
  let seconds = d.getSeconds();
  let s;
  s = year + '-' + (mon < 10 ? '0' + mon : mon) + '-' + (day < 10 ? '0' + day : day) + '   ' + (hours < 10 ? '0' + hours : hours) + ':' + (minutes < 10 ? '0' + minutes : minutes);
  return s;
}

const monthDayHourMinutes  = function(isDate) {
  if(!isDate) return '';
  var d = new Date(isDate);
  var year = d.getFullYear();
  var mon = d.getMonth() + 1;
  var day = d.getDate();
  let hours = d.getHours();
  let minutes = d.getMinutes();
  let seconds = d.getSeconds();
  let s;
  s = (mon < 10 ? '0' + mon : mon) + '-' + (day < 10 ? '0' + day : day) + '   ' + (hours < 10 ? '0' + hours : hours) + ':' + (minutes < 10 ? '0' + minutes : minutes);
  return s;
}
const yearMonthDay  = function(isDate) {
  if(!isDate) return '';
  var d = new Date(isDate);
  var year = d.getFullYear();
  var mon = d.getMonth() + 1;
  var day = d.getDate();
  let hours = d.getHours();
  let minutes = d.getMinutes();
  let seconds = d.getSeconds();
  let s;
  s = year + '-' + (mon < 10 ? '0' + mon : mon) + '-' + (day < 10 ? '0' + day : day);
  return s;
}

const MonthDay  = function(isDate) {
  if(!isDate) return '';
  var d = new Date(isDate);
  var year = d.getFullYear();
  var mon = d.getMonth() + 1;
  var day = d.getDate();
  let hours = d.getHours();
  let minutes = d.getMinutes();
  let seconds = d.getSeconds();
  let s;
  s = (mon < 10 ? '0' + mon : mon) + '-' + (day < 10 ? '0' + day : day);
  return s;
}

const hourMinutes = function(isDate) {
    if(!isDate) return '';
    var d = new Date(isDate);
    var year = d.getFullYear();
    var mon = d.getMonth() + 1;
    var day = d.getDate();
    let hours = d.getHours();
    let minutes = d.getMinutes();
    let seconds = d.getSeconds();
    let s;
    s = (hours < 10 ? '0' + hours : hours) + ':' + (minutes < 10 ? '0' + minutes : minutes);
    return s;
}

const vts = function(value) {
    let tempObj = {
     'NO_UPLOAD': '未上传',
     'UPLOAD_ING':'上传中',
     'TRANSCODING': '转码中',
     'TRANS_OVER': '转码完成',
     'UPLOAD_ERROR': '上传失败',
     'TRANS_ERROR': '转码失败',
   }
   return tempObj[value] ? tempObj[value] : '未知';
}

const chineseYearMonth  = function(isDate) {
  if(!isDate) return '';
  var d = new Date(isDate);
  var year = d.getFullYear();
  var mon = d.getMonth() + 1;
  var day = d.getDate();
  let hours = d.getHours();
  let minutes = d.getMinutes();
  let seconds = d.getSeconds();
  let s;
  s = year + '-' + (mon < 10 ? '0' + mon : mon) + '-' + (day < 10 ? '0' + day : day);
  return s;
} 
const timeWeekText = function(date) {
  let timeNum = new Date(date)
  let dayNum = timeNum && timeNum.getDay()
  let textWeek = String(dayNum).replace('0', '日').replace("1","一").replace("2","二").replace("3","三").replace("4","四").replace("5","五").replace("6","六")
  return `周${textWeek}`
}

const yearMonthDayHhMmSs  = function(isDate) {
  if(!isDate) return '';
  var d = new Date(isDate);
  var year = d.getFullYear();
  var mon = d.getMonth() + 1;
  var day = d.getDate();
  let hours = d.getHours();
  let minutes = d.getMinutes();
  let seconds = d.getSeconds();
  let s;
  s = year + '-' + (mon < 10 ? '0' + mon : mon) + '-' + (day < 10 ? '0' + day : day) + '  ' + (hours < 10 ? '0' + hours : hours) + ':' + (minutes < 10 ? '0' + minutes : minutes) + ':' + (seconds < 10 ? '0' + seconds : seconds);
  return s;
}

export {
  vts,
  MonthDay,
  moneyFenToYuan,
  yearMonthDay,
  hourMinutes,
  monthDayHourMinutes,
  chineseDay,
  numberFormat,
  timeChinese,
  chineseYearMonth,
  numToWan,
  fruitNum10,
  timeWeekText,
  yearMonthDayHhMmSs
}
